var CrtLvl3 = db.getCollection('CriteriaLevel3').findOne({Name:/Palm/})

var tpl = db.getCollection('TemplateCriteria').find({CriteriaLevel3Id:CrtLvl3._id, Name: /production/i})

tpl.forEach(function (tpl)
{
    if(tpl.Name.includes("Production-")){
         db.getCollection('TemplateCriteria').update({_id:tpl._id},{$set: {Name: tpl.Name.replace("Production-","Production and distribution-")}},{multi:false})
        }
        
    if(tpl.Name.includes("(production)"))
    {
    db.getCollection('TemplateCriteria').update({_id:tpl._id},{$set: {Name: tpl.Name.replace("(production)","(production and distribution)")}},{multi:false})
        }
    }) 
    
var flt = db.getCollection('FilterCriteria').find({CriteriaLevel3Id:CrtLvl3._id, Name: /production/i})

flt.forEach(function (f)
{
        if(f.SelectedValue != null){
            if(f.Name.includes("Production-") || f.SelectedValue.includes("Production-")|| f.SelectedValueInformation.includes("Production-")){
           db.getCollection('FilterCriteria').update({_id:f._id},{$set: 
                {Name: f.Name.replace("Production-","Production and distribution-"),
                 SelectedValue : f.SelectedValue.replace("Production-","Production and distribution-"),
                 SelectedValueInformation : f.SelectedValueInformation.replace("Production-","Production and distribution-")
                 }},{multi:false})
             }
              if(f.Name.includes("(production)") || f.SelectedValue.includes("(production)")|| f.SelectedValueInformation.includes("(production)")){
            db.getCollection('FilterCriteria').update({_id:f._id},{$set: 
                {Name: f.Name.replace("(production)","(production and distribution)"),
                 SelectedValue : f.SelectedValue.replace("(production)","(production and distribution)"),
                 SelectedValueInformation : f.SelectedValueInformation.replace("(production)","(production and distribution)")  
                 }},{multi:false})
             }
            }
        else{
            if(f.Name.includes("Production-") || f.SelectedValueInformation.includes("Production-")){
             db.getCollection('FilterCriteria').update({_id:f._id},{$set: 
                {Name: f.Name.replace("Production-","Production and distribution-"),
                 SelectedValueInformation : f.SelectedValueInformation.replace("Production-","Production and distribution-")
                 }},{multi:false})
             }
              
            if(f.Name.includes("(production)") || f.SelectedValueInformation.includes("(production)")){ 
              db.getCollection('FilterCriteria').update({_id:f._id},{$set: 
                {Name: f.Name.replace("(production)","(production and distribution)"),
                 SelectedValueInformation : f.SelectedValueInformation.replace("(production)","(production and distribution)")  
                 }},{multi:false})
                }
              }
    })

db.getCollection('TemplateCriteria').find({CriteriaLevel3Id:CrtLvl3._id, Name: /production/i})

db.getCollection('FilterCriteria').find({CriteriaLevel3Id:CrtLvl3._id, Name: /production/i})
